var gulp = require('gulp'),
    minifycss = require('gulp-minify-css'),  //CSS压缩
    concat = require('gulp-concat'),        // 文件合并
    uglify = require('gulp-uglify'),        //js压缩插件
    rename = require('gulp-rename'),        // 重命名
    notify = require('gulp-notify'),        // 重命名
    less = require('gulp-less'),        // 重命名
    plumber = require('gulp-plumber')      // 解决报错停止

gulp.task('default', function() {
  // 将你的默认的任务代码放在这
});

gulp.task('watch', function() {
  gulp.watch(['public/script/*.js','public/script/*/*.js','public/script/*/*/*.js','public/script/*/*/*/*.js','public/script/*/*/*/*/*.js'],
  ['js-vendor','js-controller','js-service','js-directive','js-base']);
  gulp.watch(['public/style/*/*.less','public/style/*.less'], ['css-less', 'css-ui-less']);
});

gulp.task('js-base', function() {
  return gulp.src('public/script/*.js')
      .pipe(concat('base.js'))
      .pipe(gulp.dest('public/dest/js'))
});

gulp.task('js-vendor', function() {
  return gulp.src('public/script/vendor/*.js')
      .pipe(gulp.dest('public/dest/js'))
});

gulp.task('js-controller', function() {
  return gulp.src(['public/script/controller/*/*.js','public/script/controller/*/*/*.js'])
      .pipe(concat('controller.js'))
      .pipe(gulp.dest('public/dest/js'))
});

gulp.task('js-service', function() {
  return gulp.src('public/script/service/*/*.js')
      .pipe(concat('service.js'))
      .pipe(gulp.dest('public/dest/js'))
});

gulp.task('js-directive', function() {
  return gulp.src(['public/script/directive/*.js', 'public/script/directive/*/*.js'])
      .pipe(concat('directive.js'))
      .pipe(gulp.dest('public/dest/js'))
});

gulp.task('css-less', function() {
  return gulp.src('public/style/*/*.less')
      .pipe(plumber())
      .pipe(less())
      .pipe(gulp.dest('public/style/'))
      .pipe(notify({ message: 'less2css task ok' }));
});

gulp.task('css-ui-less', function() {
  return gulp.src('public/style/*.less')
      .pipe(plumber())
      .pipe(less())
      .pipe(gulp.dest('public/style/'))
      .pipe(notify({ message: 'less2css task ok' }));
});
